package com.ruoyi.business.manager;


import com.ruoyi.business.domain.Book;
import com.ruoyi.business.mapper.BookMapper;
import com.ruoyi.business.service.IBookService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

@Component
@Configuration //1.主要用于标记配置类，兼备Component的效果。
public class timeTask {

    @Autowired
    private IBookService bookService;

    //3.添加定时任务
    @Scheduled(cron = "0 0 20 * * ? ")
    private void configureTasks() {
        System.err.println("执行定时任务1: " + LocalDateTime.now());
        Book book = new Book();
        String temp = DateUtils.getDate();
        Date date = DateUtils.parseDate(temp);
        book.setBookTime(date);
        bookService.updateByTime(book);
    }
}

